from sympy import *
import sympy
k=Symbol('k')
q=Symbol('q')
p=Symbol('p')

q_1=Symbol('q_1')
q_2=Symbol('q_2')
q_3=Symbol('q_3')
F_2=1./(1+k**2+p**2+2*p*k*cos(q_1))

print sympy.printing.ccode(diff(F_2, p,2)/2)

